<?php 
/**
 * 鸡蛋美术 ajax加载
 * $Author: 靓崑
 * $Id: ajax_loading.php 17217 2015-7-13 18:02:08
*/
define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
require(ROOT_PATH . 'includes/cls_json.php');

$json   = new JSON;
$return = array( 'message' => '','error'=>'0','content'=>'');
assign_template();
$action=$_REQUEST['act'];
$smarty->assign('action', $action);


// AJAX记录和删除session
if($action == 'session'){
        $_SESSION[$_POST['obj']] = $_POST['msg'];
}

/* 登录弹窗 */
elseif($action == 'login'){
    $return['content'] = $smarty->fetch("library/ajax_loading.lbi");
    echo $json->encode($return);
    exit;
}

/* 忘记密码弹窗 */
elseif($action == 'retrieve_password'){
    $return['content'] = $smarty->fetch("library/ajax_loading.lbi");
    echo $json->encode($return);
    exit;
}

/* 首页鸡蛋白弹窗 */
elseif($action == 'popup_glair'){
    /*第一个弹框是否出现过*/
    if (empty($_SESSION['prompt_1'])) {
            $smarty->assign('state', '1');
            $return['content'] = $smarty->fetch("library/ajax_loading.lbi");
            $_SESSION['prompt_1'] =1;
    }
    echo $json->encode($return);
    exit;
}
/* 购物车鸡蛋白弹窗 */
elseif($action == 'cart_popup'){

    /*用户测试*/
    if ($_SESSION['user_id'] != '12') {
        echo $json->encode($return);
        exit;
    }


   if (empty($_SESSION['cart_popup'])&&!empty($_SESSION['user_id'])) {
         $sql =  'SELECT ct.type_code FROM '.$ecs->table('coupon')."AS c ".
                " LEFT JOIN ".$ecs->table('coupon_type')."AS ct ON c.type_id = ct.type_id ".
                " WHERE c.user_id = '".$_SESSION['user_id']."' AND c.is_use = 0 ";
                $coupon = $db->getAll($sql);
        if (empty($coupon)) {
            echo $json->encode($return);
            exit;
        }else{
            $states=1;
            foreach ($coupon as $key => $value) {
                if (!empty($value['type_code'])&&$value['type_code']=="discount") {
                    $states=2;
                }
            }
            $smarty->assign('states', $states);
            $return['content'] = $smarty->fetch("library/ajax_loading.lbi");
            $_SESSION['cart_popup'] =1;
            echo $json->encode($return);
            exit;
        }
   }else{
        echo $json->encode($return);
        exit;
   }



}

